package com.yjt.gcss.gddw.modules.uiPlds;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yjt.common.base.datasource.DBContextHolder;
import com.yjt.common.easyui.datagrid.DataGridDTO;
import com.yjt.common.easyui.datagrid.DataGridJsonDTO;
import com.yjt.common.model.JsonDTO;
import com.yjt.common.tools.Jackson2JsonUtil;
import com.yjt.gcss.gddw.common.bean.domain.TxnPlds;
import com.yjt.gcss.gddw.common.bean.domain.TxnSsds;
import com.yjt.gcss.gddw.common.bean.domain.UiPlds;
import com.yjt.gcss.gddw.common.bean.domain.UiSsds;
import com.yjt.gcss.gddw.modules.txnPlds.TxnPldsService;

@Controller
@RequestMapping("/gcss/gddw/UiPldsController")
public class UiPldsController {

	@Resource(name = UiPldsService.BEAN_PACKAGE_NAME)
	private UiPldsService uiPldsService;
	
	@Resource(name = TxnPldsService.BEAN_PACKAGE_NAME)
	private TxnPldsService txnPldsService;
	
	@RequestMapping("/index")
	public String index() {
		return "/WEB-INF/admin/gcss/gddw/uiPlds/index";
	}
	
	@RequestMapping("/query")
	@ResponseBody
	public DataGridJsonDTO query(UiPlds queryModel, HttpServletRequest request) {
		DBContextHolder.setDBType(DBContextHolder.GDDW_SESSION_FACTORY);
		return uiPldsService.query(new DataGridDTO(request), queryModel);
	}
	
	@RequestMapping("/view")
	public String view(@RequestParam(required = true)String msgId, HttpServletRequest request) {
		UiPlds uiPldsQueryModel = new UiPlds();
		uiPldsQueryModel.setMsgId(msgId);
		DBContextHolder.setDBType(DBContextHolder.GDDW_SESSION_FACTORY);
		uiPldsQueryModel = uiPldsService.getUiPldsByQueryModel(uiPldsQueryModel);
		TxnPlds txnPldsQueryModel = new TxnPlds();
		txnPldsQueryModel.setReqMsgId(msgId);
		DBContextHolder.setDBType(DBContextHolder.GDDW_SESSION_FACTORY);
		txnPldsQueryModel = txnPldsService.getTxnPldsByQueryModel(txnPldsQueryModel);
		//转化成Json对象，方便页面操作
		try {
			request.setAttribute("uiPldsJson", Jackson2JsonUtil.beanToJson(uiPldsQueryModel));
			request.setAttribute("txnPldsJson", Jackson2JsonUtil.beanToJson(txnPldsQueryModel));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "/WEB-INF/admin/gcss/gddw/uiPlds/view";
	}
}
